<?php
/**
* activity.php
*
* Create on 2015-8-5
* Create by TT
*/
namespace haibao\app\data;
use \haibao\app\model\filter\Activity as ActivityFilter;

class Activity extends \haibao\app\data\BaseMysql {
	public function __construct() {
		parent::__construct ( '\haibao\app\model\data\ActivityProperty' );
	}
	
	/**
	 * 修改活动
	 * @param \haibao\app\model\data\Article $model
	 */
	public function updateActivity($model){
	}
	
	public function updateStatus($id,$status = \haibao\app\model\data\Article::STATUS_DISABLE){
	}
	
	public function updateCommentClick($id){
	}
	
	/**
	 * 计划任务，判断活动是否已经结束
	 */
	public function setActivityEnd(){
		$activityId = array();
		$today = date('Y-m-d H:i:s',time());
		$sql="select a.Id,ap.EndTime from Article a LEFT JOIN ActivityProperty ap on a.Id=ap.ArticleId where a.Type = 2 and a.Published = 1 and a.Status = 1 and ap.EndTime<='".$today."' ";
		$result = $this->query($sql);
		while($result->fetch_assoc()){
			$activityId[] = $result->getData('Id');
		}
		if($activityId){
			$Ids = join(',',$activityId);
			$sql = "update Article set Published=4 where Id in (".$Ids.")  ";
			$this->query ( $sql );
		}
	}
	
	
	public function getClickByArticleIds($articleIds){
		$str = preg_replace('/(\d+)/', '%s', implode(',', $articleIds));
		$sql = "select ArticleId,AppClickNum from ArticleProperty where ArticleId in (".$str.")";
		$result = $this->query($sql,$articleIds);
		$resArr = array();
		while($result->fetch_assoc()){
			$resArr[$result->getData('ArticleId')] = $result->getData('AppClickNum');
		}
		
		return $resArr;
	}
}